package freshmanspecial.mredrock.com.welcomefreshman.Util;

import android.app.ActionBar;
import android.app.Dialog;
import android.content.Context;
import android.content.DialogInterface;
import android.support.annotation.NonNull;
import android.support.annotation.StyleRes;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;

import freshmanspecial.mredrock.com.welcomefreshman.R;

/**
 * Created by HP on 2017/8/12.
 */

public class CustomDialog extends Dialog {
    public CustomDialog(@NonNull Context context, @StyleRes int themeResId) {
        super(context, themeResId);
    }

    public CustomDialog(@NonNull Context context) {
        super(context);
    }


    public static class Builder {
        private Context context;
        private String name;
        private String message;
        private View contentView;
        private DialogInterface.OnClickListener negativeButtonClickListener;
        private String url;
        public Builder(Context context) {
            this.context = context;
        }

        public Builder setMessage(String message) {
            this.message = message;
            return this;
        }
        public Builder setTitle(String name) {
            this.name = name;
            return this;
        }
        public Builder setContentView(View v) {
            this.contentView = v;
            return this;
        }
        public  Builder setUrl(String url){
            this.url = url;
            return this;
        }

        public  Builder setNegativeButton(DialogInterface.OnClickListener listener){
            this.negativeButtonClickListener = listener;
            return this;
        }

        public CustomDialog create() {
            final CustomDialog dialog = new CustomDialog(context);
            LayoutInflater inflater = (LayoutInflater) context
                    .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            View layout = inflater.inflate(R.layout.special_2017_dialog_normal_layout, null);
            dialog.addContentView(layout, new WindowManager.LayoutParams(
                    ActionBar.LayoutParams.FILL_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT));
            ((TextView) layout.findViewById(R.id.dialot_name)).setText(name);
            ((TextView) layout.findViewById(R.id.dialot_jianjie)).setText(message);
            Glide.with(context).load(url).into((ImageView) layout.findViewById(R.id.dialog_img));

            if (negativeButtonClickListener != null) {
                ((ImageView) layout.findViewById(R.id.dialog_exit)).setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View view) {
                        negativeButtonClickListener.onClick(dialog,
                                DialogInterface.BUTTON_NEGATIVE);
                    }
                });

            }
                return dialog;
        }




        }

}
